#include "FunctionSelectWindow.h"
#include "MatrixTransformationWindow.h"
#include "MatrixDecompositionWindow.h"
#include "LinearEquationWindow.h"
#include "GeometricTransformationWindow.h"

#include <QVBoxLayout>
#include <QWidget>

FunctionSelectWindow::FunctionSelectWindow(QWidget *parent)
    : QMainWindow(parent)
{
    setupUi();
}

void FunctionSelectWindow::setupUi() {
    auto *central = new QWidget(this);
    auto *layout = new QVBoxLayout(central);
    layout->setSpacing(20);
    layout->setContentsMargins(50, 50, 50, 50);

    btnTransform_ = new QPushButton(tr("向量与矩阵变换"));
    btnDecomp_    = new QPushButton(tr("矩阵分解"));
    btnEquation_  = new QPushButton(tr("线性方程组求解"));
    btnGeometry_  = new QPushButton(tr("几何变换"));

    for (auto *btn : {btnTransform_, btnDecomp_, btnEquation_, btnGeometry_}) {
        btn->setMinimumHeight(40);
        layout->addWidget(btn);
    }
 // 按钮绑定
    connect(btnTransform_, &QPushButton::clicked, this, &FunctionSelectWindow::onTransformClicked);
    connect(btnDecomp_, &QPushButton::clicked, this, &FunctionSelectWindow::onDecompositionClicked);
    connect(btnEquation_, &QPushButton::clicked, this, &FunctionSelectWindow::onEquationClicked);
    connect(btnGeometry_, &QPushButton::clicked, this, &FunctionSelectWindow::onGeometryClicked);

    setCentralWidget(central);
    setWindowTitle(tr("功能选择"));
    resize(400, 300);
}

//功能按钮响应：打开各自的功能窗口
void FunctionSelectWindow::onTransformClicked() {
    auto *win = new MatrixTransformationWindow();
    win->setAttribute(Qt::WA_DeleteOnClose);
    win->setWindowTitle("向量与矩阵变换");
    win->resize(800, 600);
    win->show();
}

void FunctionSelectWindow::onDecompositionClicked() {
    auto *win = new MatrixDecompositionWindow();
    win->setAttribute(Qt::WA_DeleteOnClose);
    win->setWindowTitle("矩阵分解");
    win->resize(800, 600);
    win->show();
}

void FunctionSelectWindow::onEquationClicked() {
    auto *win = new LinearEquationWindow();
    win->setAttribute(Qt::WA_DeleteOnClose);
    win->setWindowTitle("线性方程组求解");
    win->resize(800, 600);
    win->show();
}

void FunctionSelectWindow::onGeometryClicked() {
    auto *win = new GeometricTransformationWindow();
    win->setAttribute(Qt::WA_DeleteOnClose);
    win->setWindowTitle("几何变换");
    win->resize(800, 600);
    win->show();
}
